import logging
import threading
import yaml_handle

class LogNote():
    def __init__(self):
        self.path = "..\log\TestLog.log"
        self.logger = logging.getLogger("MainLog")
        self.logger.setLevel(logging.INFO)
        self.formater = logging.Formatter("%(asctime)s--%(filename)s[line:%(lineno)d]--%(levelname)s:%(message)s",
                                        datefmt="%Y/%m/%d-%H:%M:%S")
        self.level = logging.DEBUG
        self.Chandle = logging.StreamHandler()
        self.Fhandle = logging.FileHandler(self.path)
        self.Fhandle.setFormatter(self.formater)
        self.Fhandle.setLevel(self.level)
        self.Chandle.setLevel(self.level)
        self.logger.addHandler(self.Fhandle)
        self.logger.addHandler(self.Chandle)

    def get_logger(self,name):
        return logging.getLogger("MainLog."+name)

class Log():
    log = None
    mux = threading.Lock()
    def __init__(self):
        pass

    @staticmethod
    def get_log(name):
        if Log.log == None:
            Log.mux.acquire()
            Log.log = LogNote().get_logger(name)
            Log.mux.release()
        return Log.log
#
if __name__ == '__main__':
    logs = Log.get_log(__name__)
    logs.warning("sad")
    print(logs.parent)